// #include <pthread.h>
// int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg);

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <errno.h>
#include <pthread.h>

#define ERRLOG() printf("[file:%s][func:%s][line:%d]\n",__FILE__,__func__,__LINE__);
#define INFO(fmt,...) printf(fmt,##__VA_ARGS__);

void* pthread_func(void* arg){
    pthread_detach(pthread_self());
    INFO("pthread_self()=%ld\n",pthread_self());
    int num=0;
    while(1){
        INFO("线程创建成功,正在运行线程\n");
        fflush(stdout);
        if(num>5){
            break;
        }
        num++;
        sleep(1);
    }
    kill(getpid(),SIGUSR1);
    // pthread_exit("线程退出");
}

void handler(int arg){
    // raise(SIGKILL);
    exit(0);
}

int main(int argc, char const *argv[])
{
    signal(SIGUSR1,handler);
    pthread_t pthread;
    if(pthread_create(&pthread,NULL,pthread_func,NULL)!=0){
        printf("errno=%d\n",errno);
        ERRLOG();
        exit(-1);
    }
    INFO("pthread=%ld\n",pthread);
    while(1);
    // void *exitlog=NULL;
    // pthread_join(pthread,&exitlog);
    // INFO("%s\n",(char *)exitlog);
    return 0;
}
